import request from './request'

// 公告类型定义
export interface Notice {
  id: number
  title: string
  content: string
  status: 'draft' | 'published' | 'expired'
  publish_date: string
  expire_date: string
  author: string
  created_at: string
  updated_at: string
}

export interface NoticeListResponse {
  count: number
  next: string | null
  previous: string | null
  results: Notice[]
}

export interface NoticeForm {
  title: string
  content: string
  publish_date: string
  expire_date: string
  status: 'draft' | 'published'
}

// 敏感词类型定义
export interface SensitiveWord {
  id: number
  word: string
  category: string
  level: 'low' | 'medium' | 'high'
  replace_word: string
  created_at: string
  updated_at: string
  level_display?: string
}

export interface SensitiveWordListResponse {
  count: number
  next: string | null
  previous: string | null
  results: SensitiveWord[]
}

export interface SensitiveWordForm {
  word: string
  category: string
  level: 'low' | 'medium' | 'high'
  replace_word?: string
}

// 公告相关API
export function getNotices(params?: { 
  page?: number; 
  page_size?: number;
  title?: string;
  status?: string;
}) {
  return request<NoticeListResponse>({
    url: '/health/notices/',
    method: 'get',
    params
  })
}

export function createNotice(data: NoticeForm) {
  return request<Notice>({
    url: '/health/notices/',
    method: 'post',
    data
  })
}

export function updateNotice(id: number, data: NoticeForm) {
  return request<Notice>({
    url: `/health/notices/${id}/`,
    method: 'put',
    data
  })
}

export function deleteNotice(id: number) {
  return request({
    url: `/health/notices/${id}/`,
    method: 'delete'
  })
}

// 敏感词相关API
export function getSensitiveWords(params?: { 
  page?: number; 
  page_size?: number;
  keyword?: string;
}) {
  return request<SensitiveWordListResponse>({
    url: '/health/sensitive-words/',
    method: 'get',
    params
  })
}

export function createSensitiveWord(data: SensitiveWordForm) {
  return request<SensitiveWord>({
    url: '/health/sensitive-words/',
    method: 'post',
    data
  })
}

export function updateSensitiveWord(id: number, data: SensitiveWordForm) {
  return request<SensitiveWord>({
    url: `/health/sensitive-words/${id}/`,
    method: 'put',
    data
  })
}

export function deleteSensitiveWord(id: number) {
  return request({
    url: `/health/sensitive-words/${id}/`,
    method: 'delete'
  })
}